package org.intrasearch.spider;

import com.google.inject.Singleton;

@Singleton
public class MemoryUsageStatusImpl implements MemoryUsageStatus
{
    public double usedToAllocatedRatio()
    {
        Runtime runtime = Runtime.getRuntime();
        double ratio = runtime.totalMemory() * 1.0 / runtime.maxMemory();
        double freeRatio = 1.0 - runtime.freeMemory() * 1.0 / runtime.maxMemory();
        ratio = Math.min(ratio, freeRatio);
        return ratio;
    }
}
